package com.linln.modules.member.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.linln.common.data.PageSort;
import com.linln.modules.member.domain.MemberDayCount;
import com.linln.modules.member.repository.MemberDayCountRepository;
import com.linln.modules.member.service.MemberDayCountService;
import com.linln.modules.system.domain.Dept;
import com.linln.modules.system.domain.User;

/**
 * @author hct
 * @date 2019/09/12
 */
@Service
public class MemberDayCountServiceImpl implements MemberDayCountService {

    @Autowired
    private MemberDayCountRepository memberDayCountRepository;

    /**
     * 根据ID查询数据
     * @param id 主键ID
     */
    @Override
    @Transactional
    public MemberDayCount getById(Long id) {
        return memberDayCountRepository.findById(id).orElse(null);
    }
   
   @Override
    public   Boolean delCollect(Long id){
	   boolean isOk=false;
	   try{
		   memberDayCountRepository.deleteById(id);
        isOk=true;
	   }catch(Exception e){
		   
	   }
       return isOk;
   }
    
    /**
     * 获取分页列表数据
     * @param example 查询实例
     * @return 返回分页数据
     */
    @Override
    public Page<MemberDayCount> getPageList(Example<MemberDayCount> example) {
        // 创建分页对象
        PageRequest page = PageSort.pageRequest();
        return memberDayCountRepository.findAll(example, page);
    }

   public List<MemberDayCount> getList(Example<MemberDayCount> example){
        return memberDayCountRepository.findAll(example);

    }

    /**
     * 保存数据
     * @param MemberDayCount 实体对象
     */
    @Override
    public MemberDayCount save(MemberDayCount MemberDayCount) {
        return memberDayCountRepository.save(MemberDayCount);
    }

	/**
	     * 定时任务
	* @return
	*/
	public Integer insert() {
                if(memberDayCountRepository.dayCount()>0){
                    return 0;
                }else{
                    return memberDayCountRepository.insert();
                }
	}
    /**
     * 定时任务
     * @return
     */
    public Integer dayCount() {

        return memberDayCountRepository.dayCount();
    }

    @Override
    public Map<String, Integer> statisticMemberDayCount() {
        return memberDayCountRepository.statisticMemberDayCount();
    }

    @Override
    public Map<String, Integer> statisticStoreDayCount() {
        return memberDayCountRepository.statisticStoreDayCount();
    }

    @Override
    public Map<String, Integer> statisticMemberPayDayCount() {
        return memberDayCountRepository.statisticMemberPayDayCount();
    }

    @Override
    public Map<String, Integer> statisticMessageDayCount() {
        return memberDayCountRepository.statisticMessageDayCount();
    }
}